﻿using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Media;

namespace LearnWPFDemo
{
    public class MainViewModel : INotifyPropertyChanged
    {
        //MainWindow _mainWindow;
        //public MainViewModel(MainWindow mainWindow)
        //{
        //    _mainWindow = mainWindow;
        //}

        private string _value = "test";
        public string Value
        {
            get => _value;
            set
            {
                _value = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
                if (value == "100") ValueColor = Brushes.Blue;
            }
        }
        public Brush ValueColor
        {
            get => _valueColor;
            set
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ValueColor"));
                _valueColor = value;
            }
        }

        private Brush _valueColor = Brushes.Orange;

        public event PropertyChangedEventHandler? PropertyChanged;

        private ICommand _valueCommand;

        public ICommand ValueCommand
        {
            get
            {
                if (_valueCommand is null)
                    _valueCommand = new CommandBase() { DoAction = new System.Action<object>(ValueCommandAction) };

                return _valueCommand;
            }
            set { _valueCommand = value; }
        }

        private void ValueCommandAction(object obj)
        {
            Value = "100";
        }
    }
}
